load("@rules_cc//cc:cc_library.bzl", "cc_library")

cc_library(
    name = "common",
    srcs = [
        "lib/md5.c",
        "lib/randutils.c",
        "lib/sha1.c",
        "lib/strutils.c",
        "lib/timeutils.c",
    ],
    hdrs = [
        "include/all-io.h",
        "include/bitops.h",
        "include/c.h",
        "include/md5.h",
        "include/nls.h",
        "include/pathnames.h",
        "include/randutils.h",
        "include/sha1.h",
        "include/strutils.h",
        "include/timeutils.h",
    ],
    copts = [
        "-Wno-implicit-function-declaration",
        "-Wno-return-type",
    ],
    defines = [
        "HAVE_NANOSLEEP",
        "_PATH_LOCALSTATEDIR=\\\"/var\\\"",
    ] + select({
        "@platforms//os:linux": ["HAVE_REALLOCARRAY"],
        "//conditions:default": [],
    }),
    includes = ["include"],
)

cc_library(
    name = "uuid",
    srcs = [
        "libuuid/src/clear.c",
        "libuuid/src/compare.c",
        "libuuid/src/copy.c",
        "libuuid/src/gen_uuid.c",
        "libuuid/src/isnull.c",
        "libuuid/src/pack.c",
        "libuuid/src/parse.c",
        "libuuid/src/predefined.c",
        "libuuid/src/unpack.c",
        "libuuid/src/unparse.c",
        "libuuid/src/uuidP.h",
        "libuuid/src/uuid_time.c",
        "libuuid/src/uuidd.h",
    ],
    hdrs = [
        "libuuid/src/uuid.h",
    ],
    copts = [
        "-Wno-implicit-function-declaration",
        "-Wno-unused-parameter",
    ],
    defines = [
        "_PATH_LOCALSTATEDIR=\\\"/var\\\"",
    ],
    include_prefix = "uuid",
    strip_include_prefix = "libuuid/src",
    visibility = ["//visibility:public"],
    deps = [
        ":common",
    ],
)

alias(
    name = "libuuid",
    actual = ":uuid",
    visibility = ["//visibility:public"],
)
